/**
 * 
 */
package ua.kiev.ntukpi.asu.ga.impl;

import java.util.List;

import ua.kiev.ntukpi.asu.ga.Individual;
import ua.kiev.ntukpi.asu.ga.interfaces.Algorithm;
import ua.kiev.ntukpi.asu.ga.interfaces.Crossover;
import ua.kiev.ntukpi.asu.ga.interfaces.Fitness;
import ua.kiev.ntukpi.asu.ga.interfaces.Mutation;
import ua.kiev.ntukpi.asu.ga.interfaces.Remover;
import ua.kiev.ntukpi.asu.ga.interfaces.Selection;

/**
 * @author Alexander Galibey
 *
 */
public class CanonicalAligorithm implements Algorithm {

	private Crossover crossover = new CrossoverOneDot();
	
	private Fitness fitness = new FitnessImpl();
	
	private Mutation mutation = new MutationPlain();
	
	private Selection selection = new SelectionBest(fitness);
	
	private Remover remover = new RemoverWorst(fitness);
	
	public Crossover getCrossover() {
		
		return this.crossover;
	}

	public Fitness getFitness() {
		
		return this.fitness;
	}

	public Mutation getMutation() {
		
		return this.mutation;
	}

	public Remover getRemover() {
		
		return this.remover;
	}

	public Selection getSelection() {

		return this.selection;
	}

	public void nextGeneration(List<Individual> population) {
		
		List<Individual> parents = selection.select(population);
		List<Individual> childs = crossover.cross(parents, 0.3);
		mutation.mutate(childs, 0.3);
		population.addAll(childs);
		remover.remove(population, parents, childs);
	}

}
